//
//  CoMeTAPI.m
//  CoMeT
//
//  Created by paws guest on 8/1/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CoMeTAPI.h"
#import "TBXML.h"
#import "NetUtil.h"


@implementation CoMeTAPI


+(void) bookmark:(NSString *)cid{
    
    if ([NetUtil checkNetworkStatus:nil]== 0 ) {
        UIAlertView *alertfailure = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Network Connection! Please open your wifi or wwan connection"
                                                              delegate:self cancelButtonTitle:@"Return" otherButtonTitles:nil, nil];
        [alertfailure show];
        [alertfailure release];
        
        return;
        
    }
    NSLog(@"Network is OK");
    
    NSString *postSchedule =[NSString stringWithFormat:@"user_id=%@&col_id=%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"userid"],cid];
    NSString *hostStrSchedule = @"http://halley.exp.sis.pitt.edu/comet/utils/addBookmarkXML.jsp?";
    hostStrSchedule = [hostStrSchedule stringByAppendingString:postSchedule];
    
    NSURL *urlSchedule=[[NSURL alloc] initWithString:hostStrSchedule];
    
    NSMutableURLRequest *urlRequestSch=[NSMutableURLRequest requestWithURL:urlSchedule];
    [urlSchedule release];
    
    //[urlRequestSch setHTTPMethod:@"POST"];
    //[urlRequestSch setHTTPBody:[postSchedule dataUsingEncoding:NSASCIIStringEncoding]];
    //[urlRequestSch setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    
    NSLog(@"Ready to sendf Request");
    
    NSURLResponse *responseSch;
    NSError *errorSch;
    NSData *aDataSch = [NSURLConnection sendSynchronousRequest:urlRequestSch returningResponse:&responseSch error:&errorSch];
    NSString *serverOutputSch = [[NSString alloc] initWithData:aDataSch encoding: NSUTF8StringEncoding];
    
    NSLog(@"Response received");
    [serverOutputSch release];
    
}


+(void) unBookmark:(NSString *)cid{
    
    
    if ([NetUtil checkNetworkStatus:nil]== 0 ) {
        UIAlertView *alertfailure = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Network Connection! Please open your wifi or wwan connection"
                                                              delegate:self cancelButtonTitle:@"Return" otherButtonTitles:nil, nil];
        [alertfailure show];
        [alertfailure release];
        
        return;
        
    }
    NSString *postSchedule =[NSString stringWithFormat:@"user_id=%@&col_id=%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"userid"],cid];
    NSString *hostStrSchedule = @"http://halley.exp.sis.pitt.edu/comet/utils/removeBookmarkXML.jsp?";
    hostStrSchedule = [hostStrSchedule stringByAppendingString:postSchedule];
    
    NSURL *urlSchedule=[[NSURL alloc] initWithString:hostStrSchedule];
    
    NSMutableURLRequest *urlRequestSch=[NSMutableURLRequest requestWithURL:urlSchedule];
    [urlSchedule release];
    
    [urlRequestSch setHTTPMethod:@"POST"];
    [urlRequestSch setHTTPBody:[postSchedule dataUsingEncoding:NSASCIIStringEncoding]];
    [urlRequestSch setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    
    
    NSURLResponse *responseSch;
    NSError *errorSch;
    NSData *aDataSch = [NSURLConnection sendSynchronousRequest:urlRequestSch returningResponse:&responseSch error:&errorSch];
    NSString *serverOutputSch = [[NSString alloc] initWithData:aDataSch encoding: NSUTF8StringEncoding];
    
    
    [serverOutputSch release];
}





@end
